#include "comm.hpp"

int main()
{
    key_t key = getkey();
    printf("key:0x%x\n", key);
    int shmid = getShm(key);
    printf("shmid:%d\n", shmid);

    char *start = (char *)attachShm(shmid);
    printf("attach success, address start: %p\n", start);

    const char *message = "hello server, 我是另一个进程，正在和你通信";
    pid_t id = getpid();
    int cnt = 1;
    // char buffer[1024];
    while (true)
    {
        snprintf(start, MAX_SIZE, "%s[pid:%d][消息编号%d]", message, id, cnt++);
        // snprintf(buffer, sizeof(buffer), "%s[pid:%d][消息编号:%d]", message, id, cnt++);
        // memcpy(start, buffer, strlen(buffer)+1);
        // pid, count, message
        sleep(1);
    }

    detachShm(start);

    return 0;
}